package com.sky.controller.user;

import com.alibaba.fastjson.JSON;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.websocket.WebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController("userordercontroller")
@Api(tags = "C端订单相关接口")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderservice;
    @Autowired
    private WebSocketServer webSocketServer;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> orderSubmit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("提交订单:{}", ordersSubmitDTO);
       OrderSubmitVO orderSubmitVO=orderservice.submit(ordersSubmitDTO);
       return Result.success(orderSubmitVO);


    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderservice.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
@GetMapping("/orderDetail/{id}")
@ApiOperation("订单详情")
    public Result<OrderVO> getOrderDetail(@PathVariable("id") Long orderId)  {
        log.info("查看订单详情:{}",orderId);
        OrderVO orderVO =orderservice.getorderdetail(orderId);
        return Result.success(orderVO);
    }
    @GetMapping("/historyOrders")
    @ApiOperation("历史订单分页查询")
    public Result<PageResult> historypage(int page, int pageSize, Integer status){

        log.info("订单历史分页查询");
        PageResult page1=orderservice.historypage(page,pageSize,status);
        return Result.success(page1);
    }
    @PutMapping("/cancel/{id}")
    public Result CancelOreder(@PathVariable("id") Long id){
        log.info("取消订单:{}",id);
        orderservice.cancelorder(id);
        return Result.success();
    }
@PostMapping("/repetition/{id}")
    public Result openanotherorder(@PathVariable Long id){
        log.info("再来一单:{}",id);
        orderservice.openanotherorder(id);
        return Result.success();

    }
    @GetMapping("/reminder/{id}")
    @ApiOperation("用户催单")
    public Result cuidan(@PathVariable Long id){
        log.info("用户催单");

orderservice.cuidan(id);
        return Result.success();
    }



}
